#ifndef CS488_PRIMITIVE_HPP
#define CS488_PRIMITIVE_HPP

#include "algebra.hpp"
#include "polyroots.hpp"
#include "ray.hpp"

class Primitive {
public:
  virtual ~Primitive();
virtual bool RayIntersect(Ray ray, Intersection *intersection)=0;
};

class NonhierSphere : public Primitive {
public:
  NonhierSphere(const Point3D& pos, double radius)
    : m_pos(pos), m_radius(radius)
  {
  }
  virtual ~NonhierSphere();
virtual bool RayIntersect(Ray ray, Intersection *intersection);
private:
  Point3D m_pos;
  double m_radius;
};

class Sphere : public Primitive {
public:
	Sphere();
  virtual ~Sphere();
virtual bool RayIntersect(Ray ray, Intersection *intersection);
private:
	NonhierSphere *m_sphere;
};

class NonhierBox : public Primitive {
public:
  NonhierBox(const Point3D& pos, double size, Vector3D diff = Vector3D())
    : m_pos(pos), m_size(size)
  {
	if(size>=0){
		near_vectex = m_pos;
		far_vectex = Point3D(m_pos[0]+m_size,m_pos[1]+m_size,m_pos[2]+m_size);
	}
	else{
		near_vectex = m_pos;
		far_vectex = near_vectex + diff;
	}
  }
  virtual ~NonhierBox();
virtual bool RayIntersect(Ray ray, Intersection *intersection);
private:
  Point3D m_pos;
  double m_size;
	Point3D near_vectex;
	Point3D far_vectex;
};

class Cube : public Primitive {
public:
	Cube();
  virtual ~Cube();
virtual bool RayIntersect(Ray ray, Intersection *intersection);
private:
	NonhierBox *m_box;
};

#endif
